const Authority = require('../modules/Authority');

let AuthorityController = {

    //增加权限
    post_add: async function(req, res) {
        let authority = '';
        let url = '';
        let parentId = 0;
        if (req.body.authorityVal) {
            authority = req.body.authorityVal;
        }
        if (req.body.urlVal) {
            url = req.body.urlVal;
        }
        if (req.body.parentId) {
            parentId = req.body.parentId;
        }
        // console.log(req.body);
        await Authority.add_authority(authority, url, parentId);
        res.send({
            'code': 200,
            'msg': '添加成功'
        })
    },

    //删除权限
    post_delete: async function(req, res) {
        let authority = '';
        if (req.body.authority) {
            authority = req.body.authority;
        }
        authority = authority.trim();
        // console.log(authority);
        await Authority.delete_authority(authority);
        res.send({
            'code': 200,
            'msg': '删除成功'
        })
    }
}

module.exports = AuthorityController;